﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
using Utils;
//Remover aqui:
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace WebUI.Pages
{
    public partial class mgrTypes : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get credentials
            UserController usrController = new UserController();
            TypeController tpController = new TypeController();
            int idUsuario = usrController.GetUserID(User.Identity.Name);
            int idTeam = usrController.GetUserTeamID(idUsuario);

            if (idTeam != 9)
            {
                Response.Redirect("../Pages/403.aspx");
            }

            if (!this.IsPostBack)
            {
                rpTypes.DataSource = tpController.GetRequestTypes();
                rpTypes.DataBind();
            }
        }

        protected void cmdInsere_Click(object sender, EventArgs e)
        {
            ConnectionManager connMgr = new ConnectionManager();
            SqlCommand qryX = new SqlCommand(@"INSERT INTO TiposSolicitacao (DescTipoSolicitacao) VALUES (@Desc)");
            qryX.Parameters.AddWithValue("@Desc",txtNome.Text);
            
            try
            {
                connMgr.doCommand(qryX);
            }
            catch (Exception ex)
            {
                lblMsg.Text = "Erro ao cadastrar o novo Tipo de Solicitação.";
            }
            finally
            {
                txtNome.Text = "";
            }
            Response.Redirect("../Pages/mgrTypes.aspx");
        }

        protected void rpTypes_onItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "cmdEdit")
            {
                Response.Redirect("../Pages/editType.aspx?id=" + e.CommandArgument.ToString());
            }
        }
    }
}